﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class master : System.Web.UI.MasterPage
{
    public DataTable dtMenu = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public string HtmlWriteMenu()
    {
        string IdMenuSelect = Request.QueryString.Get("menu") != null ? Request.QueryString.Get("menu").ToString() : "";
        string classActive = "";
        string ActiveHome = "";
        if (IdMenuSelect == "")
        {
            ActiveHome += " class='active' ";
        }
        string htmlCode = "<li><a " + ActiveHome + " href=\"http://lanhdaitourist.com\" title='Du lịch Lanh Đại'>Trang chủ</a></li>";
        dtMenu = DataAccess.ExeSQLToDataTable("SELECT * FROM dev_menu WHERE status = 1 ORDER BY menu_order ASC");
        if (dtMenu.Rows.Count > 0)
        {
            foreach (DataRow item in dtMenu.Rows)
            {
                if (item["idparent"].ToString() == "0")
                {
                    if (IdMenuSelect == item["idmenu"].ToString())
                    {
                        classActive = " class='active' ";
                    }
                    htmlCode += "<li><a " + classActive + " href='" + item["link_page"] + item["link_web"] + "' title='" + item["name_menu"].ToString().ToLower() + "'>" + item["name_menu"] + "</a>";
                    if (Convert.ToBoolean(item["has_child"].ToString()))
                    {
                        string parent = item["idmenu"].ToString();
                        htmlCode += "<div class=\"sub\"><div class=\"sub_body\"><ul>";
                        foreach (DataRow item_child in dtMenu.Rows)
                        {
                            if (item_child["idparent"].ToString() == parent)
                            {
                                htmlCode += "<li><a href='" + item_child["link_page"] + item_child["link_web"] + "' title='" + item_child["name_menu"].ToString().ToLower() + "'>" + item_child["name_menu"] + "</a></li>";
                            }
                        }
                        htmlCode += "</ul></div></div></li>";
                    }
                    else
                        htmlCode += "</li>";
                }
                classActive = "";
            }
        }

        return htmlCode;
    }
    protected string loadfooter()
    {
        string html = "";
        DataTable dtfooter = DataAccess.ExeSQLToDataTable("select  top(1) * from Footer");
        if (dtfooter.Rows.Count > 0)
        {
            for (int i = 0; i < dtfooter.Rows.Count; i++)
            {
                html += "<p class='info'>" + dtfooter.Rows[i][1].ToString() + "</p> <p class='copy'>" + dtfooter.Rows[i][2].ToString() + "</p>";
            }
        }

        return html;
    }

    public string HtmlWriteBanner()
    {
        string htmlCode = "";
        DataTable dtbanner = DataAccess.ExeSQLToDataTable("SELECT TOP(1) * FROM banner WHERE ViTri = 1");
        if (dtbanner.Rows.Count > 0)
        {
            foreach (DataRow item in dtbanner.Rows)
            {
                htmlCode += item["Image"].ToString();
            }
        }
        return htmlCode;
    }
}
